<?php

namespace App\Http\Controllers\home\collect;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use DB;

class collectController extends Controller
{
    //收藏
    public function index()
    {
    	$data = DB::table('collect')
    		->leftJoin('goods', 'collect.goods_id', '=', 'goods.id')
    		->select('goods.goods_name', 'goods.goods_price', 'collect.id', 'goods.logo')
    		->get();
        // dd($data);
    	return view('home.collect.index', ['data' => $data]);
    }

    //删除收藏
    public function delete($id)
    {
    	$data = DB::table('collect') -> delete($id);

    	return back();
    }

    //ajax实现商品收藏
    public function ajaxCollect(request $request)
    {
        $data = array();

        $data['goods_id'] =  $request -> goods_id;

        $data['ctime'] = time();

        $data['member_id'] = session('master')['id'];

        $res = DB::table('collect') -> insert($data);

        if($res)
        {
            return 1;
        }else
        {
            return 0;
        }

        return $res;
    }
}
